<?php

// user info, URL
$username = '51158405';
$password = 'gxlty725';
$url = 'http://www.cs.cityu.edu.hk/~cs4380/webservice/blog/createPost.py';














// check inputs (always assumes POST to this php page)
if ($_POST['title']) {
	$title = $_POST['title'];
} else {
	$title = 'no title';
}
if ($_POST['content']) {
	$content = $_POST['content'];
} else {
	$content = 'no content';
} 

// values to POST to url
$post_data = array (
	'title' => $title, 
	'content' => $content
);

// Open the Curl session
$session = curl_init();

// setup POST request
curl_setopt ($session, CURLOPT_URL, $url);
curl_setopt ($session, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt ($session, CURLOPT_POST, 1);
curl_setopt ($session, CURLOPT_POSTFIELDS, $post_data);

// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// Make the call
$data = curl_exec($session);
curl_close($session);

// set content to WEBPAGE
header("Content-Type: text/html");
?>

<html>
<body>
<h1>Post successful</h1>

The UUID of your new post is: 
<?php
echo $data;
?>

<p><a href=t1.html>back to form</a>
</body></html>
